#ifndef YEP_UI_RADIO_BUTTON_HPP
#define YEP_UI_RADIO_BUTTON_HPP

#include "ButtonBase.hpp"
namespace yep
{
    class RadioButton;
    struct RadioGroup
    {
        RadioButton *selected;
    };

    /**
     * @brief A simple checkbuttom
     **/
    class RadioButton:public ButtonBase
    {
    public:
        /**
         * @brief Draws
         **/
        void onDraw( SDL_Surface* screen )
        {
            style->drawRadioButton( screen, status(), text(), isFocused(), checked(), getAbsolutePosition(), getAbsoluteArea(),
                                    getTextColor(), getBackgroundColor() );
        }

        /**
         * @brief Just do the checking thing
         **/
        void onAction()
        {
            _group->selected = this;
            ButtonBase::onAction();
        }

        /**
         * @brief Constructor
         **/
        RadioButton()
        {
            _group = NULL;
        }

        /**
         * @brief Returns whether it is checked
         **/
        bool checked() const
        {
            if(_group)
                return _group->selected == this;
            return false;
        }

        /**
         * @brief Checks or unchecks
         **/
        void checked( bool value )
        {
            if(_group)
            {
                if(value)
                {
                    _group->selected = this;
                }
                else if(_group->selected == this)
                {
                    _group->selected = NULL;
                }
            }
        }

        /**
         * @brief Returns the group
         **/
        RadioGroup *group() const
        {
            return _group;
        }

        /**
         * @brief Changes the group
         **/
        void group(RadioGroup *value)
        {
            _group = value;
        }

        // Inherist docs
        virtual void autoResize()
        {
            Uint16 w, h;
            style->radioButtonArea( text(), w, h );
            Rect newArea( getRect() );
            if( newArea.w() < w )
                newArea.setW( w );
            if( newArea.h() < h )
                newArea.setH( h );
            setRect( newArea );
        }

    private:
        RadioGroup *_group;
    };

}

#endif // YEP_UI_RADIO_BUTTON_HPP

